#include "../../src/TcpServer.hpp"
#include "../../common/LoggerHelper.hpp"

LoggerHelper helper;


void on_connected(const Connection::PtrConnection& conn)
{
    LOG_DEBUG("new 了一个 Connection 对象 : conn_id : {}", conn->get_connect_id());
}

void on_message(const Connection::PtrConnection& conn, Buffer* buf)
{
    LOG_DEBUG("有消息到来 {}", buf->read_string_pop(buf->get_readable_size()));
    std::string response = "hello client !";
    conn->send(response.c_str(), response.size());
    // conn->shutdown();
}   


void on_closed(const Connection::PtrConnection& conn)
{
    LOG_DEBUG("关闭了一个connection {}", conn->get_connect_id());
}

int main()
{   
    TcpServer server(8080);
    server.set_thread_count(2);
    server.enbale_inactive_release(10);

    server.set_connected_callback(on_connected);
    server.set_closed_callback(on_closed);
    server.set_message_callback(on_message);

    server.start();

    return 0;
}